package com.jerei.web.plugin.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import ro.fortsoft.pf4j.PluginException;
import ro.fortsoft.pf4j.PluginWrapper;
import ro.fortsoft.pf4j.spring.SpringPlugin;

/**
 * Created by sunfeihu on 2016/11/30.
 */
public class BaseInitPlugin extends SpringPlugin {

    private static final Logger log = LoggerFactory.getLogger(BaseInitPlugin.class);

    public BaseInitPlugin(PluginWrapper wrapper) {
        super(wrapper);
    }

    @Override
    public void start() throws PluginException {
        log.info(this.getWrapper().getPluginId() + "启动");
    }

    @Override
    public void stop() {
        log.info(this.getWrapper().getPluginId() + "停止");
    }

    @Override
    protected ApplicationContext createApplicationContext() {
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath*:application-" + this.getWrapper().getPluginId() + ".xml");
        applicationContext.setClassLoader(getWrapper().getPluginClassLoader());
        applicationContext.refresh();
        return applicationContext;
    }

}
